<?php

namespace App\Admin\Controllers;

use App\Admin\Traits\ModelFormRelations;
use App\Models\AwardLog;
use App\Models\CardSeries;

use App\Models\Award;
use App\Models\Merchant\Gift;
use App\Models\Merchant\GiftLog;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\ModelForm;

class AwardLogController extends Controller
{
    const CATEGORY=[
        1=>'增加金币',
        2=>'增加积分',
        3=>'MARVELX限定版头像框',
        4=>'MARVELX限定版头勋章',
    ];
    use ModelFormRelations;
    public function index($parent_id){
        
        $this->parent_id = $parent_id;
        return Admin::content(function (Content $content) {
            $gift_name = CardSeries::where('id',$this->parent_id)->value('name');
            
            $content->header($gift_name.'的奖励领取记录');
            $content->body($this->grid());
        });
    }
    
    public function edit($parent_id,$id)
    {
        $this->parent_id = $parent_id;
        return Admin::content(function (Content $content) use ($id) {
            
            $content->body($this->form()->edit($id));
        });
    }
    
    /**
     * Create interface.
     *
     * @return Content
     */
    public function create($parent_id)
    {
        $this->parent_id = $parent_id;
        return Admin::content(function (Content $content) {
            
            $content->body($this->form());
        });
    }
    
    protected function grid(){
        return Admin::grid(AwardLog::class, function (Grid $grid) {
            
            $grid->model()->where('card_series_id', $this->parent_id)->orderByDesc('id');
            
            $grid->id();
            
            $grid->member()->nickname('用户昵称');
            
            $grid->status('领取状态')->display(function($status){
                return $status == 1 ? '已领取' : '';
            });
    
            $grid->created_at('领取时间');
            $grid->disableActions();
            $grid->disableCreateButton();
        });
    }
    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Admin::form(AwardLog::class, function (Form $form) {
            
        
        });
    }
}
